package com.xyd.Servlet;

import com.xyd.Biz.Impl.ProductCarBizImpl;
import com.xyd.Biz.ProductCarBiz;
import com.xyd.Entity.ProductCar;
import com.xyd.Entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @ClassName: DeleteProductCarServlet
 * @Description:
 * @Author 余全盛
 * @Date: 2021/10/16 15:02
 */
@WebServlet("/DeleteProductCarServlet")
public class DeleteProductCarServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductCarBiz productCarBiz = new ProductCarBizImpl();
        HttpSession session = req.getSession();
        String[] strProductId = req.getParameterValues("productid");
        User user = (User) session.getAttribute("user");
        System.out.println(user);
        int length = strProductId.length;
        int[] productId = new int[length];
        for (int i = 0; i < length; i++) {
            productId[i] = Integer.parseInt(strProductId[i] == null || "".equals(strProductId[i]) ? "0" : strProductId[i]);
            productCarBiz.deleteProductCarByID(productId[i], user.getUserid());
        }
        List<ProductCar> productCarList = productCarBiz.selectAllProductCarByID(user.getUserid());
        session.setAttribute("productCarList", productCarList);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductCarBiz productCarBiz = new ProductCarBizImpl();
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        productCarBiz.deleteAllProductCar(user.getUserid());
        List<ProductCar> productCarList = productCarBiz.selectAllProductCarByID(user.getUserid());
        session.setAttribute("productCarList", productCarList);
    }
}
